<template>
	<view>
		<u-form ref='uForm' :model="model">
			<u-form-item>
				<view class="inputtext">
					<view class="text">
						手机号
					</view>
					<view class="input">
						<input type="tel" placeholder="请输入手机号" v-model='model.phone' />
					</view>
				</view>

			</u-form-item>
			<view class="line"></view>
			<u-form-item class="inputtext">
				<view class="inputtext">
					<view class="text">
						密码
					</view>
					<view class="input">
						<input type="tel" placeholder="请输入密码" v-model='model.password' />
					</view>
				</view>
			</u-form-item>
			<view class="line"></view>
			<u-form-item>
				<view class="check">
					<u-checkbox-group v-model="checkboxValue1" @change="checkboxChange">
						<u-checkbox name="选中" shape="circle">
						</u-checkbox>
						<view>同意
							<text @click="" style="color:#105CF0;">用户协议</text>、及
							<text @click="" style="color:#105CF0;">隐私政策</text>
						</view>
					</u-checkbox-group>
				</view>
			</u-form-item>
			<view class="btn">
				<u-button @click='login'>登录</u-button>
			</view>
			
		</u-form>
		<view class="bottom">
			<view class="left" @click='register'>立即注册</view>
			<view class="right"  @click='forget'>忘记密码</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/api/login.js'
	import {
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				model: {
					phone: '',
					password: ''
				},
				checkboxValue1: [],
			}
		},
		methods: {
			...mapMutations(['setToken']),
			//登录
			login() {
				login({
					mobile: this.model.phone,
					password: this.model.password,
					type: 'username'
				}).then(res => {
					if (res.code != 0) {
						alert('登录失败');
						return false;
					}
					//这里是回到的登录页===》我们修改成回到首页
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						});
					}, 2000);
					//把token存储在store中
					this.setToken(res.data.access_token);
				})
			},
			register() {
				uni.navigateTo({
					url: '/pages/login/register'
				})
			},
			forget()
			{
				uni.navigateTo({
					url: '/pages/login/forget'
				})
			},
			//确认点击协议了
			checkboxChange(val) {
				this.checkboxValue1 = val;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.inputtext {
		display: flex;
		flex-direction: column;
		width: 100%;
		
		.text {
			font-size: 22px;
			margin: 10px;
		}

		.input {
			margin: 10px ;
		}

	}

	.line {
		height: 1px;
		width: 90%;
		background-color: #F1F1F1;
		margin: 0 10px;
	}
	.check
	{
		margin: 10px;
	}
	.btn
	{
		margin-top: 67px;
		/deep/.u-button--info
		{
			display: flex;
			justify-content: center;
			align-items: center;
			width: 80%;	
			background: linear-gradient(102.42deg, #0F9DED 10.57%, #105CF0 91.22%);
			border-radius: 8px;
			color: #FFF;
			height: 54px;
		}
	}
	.bottom
	{
		display: flex;
		justify-content: space-between;
		margin: 10px;
		color: #FF0404;
		.left
		{
			margin-left: 8%;
		}
		.right
		{
			margin-right: 8%;
			
		}
	}
</style>